//
//  Factory.m
//  BaseProject
//
//  Created by 孟瑞瑞 on 18/05/5.
//  Copyright © 2018年 CSDN. All rights reserved.
//

#import "Factory.h"

@interface Factory ()

@end


@implementation Factory

/*向某个控制器上,添加返回按钮*/
+(void)addBlackItemToVC:(UIViewController *)vc
{
    __weak UIViewController *weakSelf = vc;
    PPButton *btn = [PPButton buttonWithType:UIButtonTypeCustom];
    [btn theme_setImage:navBackImage forState:UIControlStateNormal]; //设置自定义返回图片
    [btn theme_setImage:navBackImage forState:UIControlStateHighlighted]; //设置自定义返回图片
    [btn setTitle:@"" forState:UIControlStateNormal];
    [btn setImageEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 0)];  //调整按钮内图片的布局
    [btn setEnlargeEdge:15];
    btn.frame = CGRectMake(0, 0, 30, 44);
    if (iPhone5) {
     btn.touchInsets = UIEdgeInsetsMake(-10, -30, -10, -20);
    }else{
    btn.touchInsets = UIEdgeInsetsMake(-10, -20, -10, -20);
    }
    [btn bk_addEventHandler:^(id sender) {
        if (weakSelf.navigationController.childViewControllers.count > 1) {
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }else{
            [weakSelf dismissViewControllerAnimated:YES completion:nil];
        }
    } forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *menuItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    //使用弹簧控件缩小菜单按钮和边缘距离
    UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    UIBarButtonItem *spaceItemRight = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    //spaceItem.width = -12;
    //spaceItemRight.width = 40;
    vc.navigationItem.leftBarButtonItems = @[spaceItem,menuItem,spaceItemRight];
    
}
@end
